package cn.changeforyou.web.controller;

import cn.changeforyou.web.dao.UserDao;
import cn.changeforyou.web.entity.User;
import cn.changeforyou.web.entity.UserDTO;
import cn.changeforyou.web.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhyu
 * @version 1.0
 * @date 2022/2/8 16:22
 */
@RestController
@RequestMapping("insert")
public class InsertController {

    @Autowired
    private UserDao userDao;

    @Autowired
    private UserService userService;

    @PostMapping("/")
    public int insert(@RequestBody User user) {
        return userDao.insert(user);
    }

    @PostMapping("/list")
    public int list(@RequestBody List<User> users) {
        return userDao.insertList(users);
    }

    @PostMapping("/dto")
    public int dto(@RequestBody UserDTO dto) {
        return userDao.insertDTO(dto);
    }

    @PostMapping("/dtos")
    public int dtoList(@RequestBody List<UserDTO> dto) {
        return userDao.insertDTOs(dto);
    }

}
